package com.admin.action;

import com.admin.service.AdminIndexService;
import com.data.bean.Account;
import com.data.util.FinalStringUtils;
import com.data.util.LoginMethodUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 首页相关
 *
 * @author: HingLo
 * @create 2017-08-29 13:04
 **/
@Controller
@RequestMapping("/indexAction/admin/")
public class AdminIndexAction {
    @Autowired
    private AdminIndexService adminIndexService;

    /**
     * 我的桌面显示信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/home")
    public String inputHomeAction(HttpServletRequest request) {
        //服务器硬件信息
        return "/WEB-INF/admin/welcome";
    }

    /**
     * 系统管理员界面
     *
     * @param request
     * @return
     */
    @RequestMapping("index")
    public String adminIndexAction(HttpServletRequest request) {
        Account account = (Account) request.getSession().getAttribute("Account");
        System.out.println(account);
        if (account != null) {
            if (LoginMethodUtils.loginAuth(account.getTypes(), FinalStringUtils.PERSON, FinalStringUtils.COMPANY, FinalStringUtils.BUILT_ADMIN)) {
                return "redirect:/indexUserAction/user/index";
            } else if (LoginMethodUtils.loginAuth(account.getTypes(), FinalStringUtils.ADMIN)) {
                return "/WEB-INF/admin/index";
            }
            else {
                return "appindex";
            }
        }
        //如果没有登录，就直接跳转到登录界面，让其登录后再查看控制中心
        return "redirect:/android/loginAction/login/input";
    }
}
